package com.Renting.Configuration;


import javax.servlet.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.io.IOException;

public class ConfigInterceptorLogin implements Filter {

    @Override
    public void init(FilterConfig filterConfig) throws ServletException {

    }

    @Override
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
        HttpServletRequest req=(HttpServletRequest)request;//向下转型
        HttpSession session=req.getSession();//获取session
        if(session.getAttribute("Message")!=null){
            chain.doFilter(request,response);
        }else{
            session.setAttribute("ErrorLogin","请先登录!");
            request.getRequestDispatcher("Login.jsp").forward(request, response);//跳转到登录页
        }
    }

    @Override
    public void destroy() {

    }
}
